package tothreedesignmodel.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author lzhphantom
 * @Description
 * @Date 创建于 11:19 2020/7/21
 * @Modified
 */
public class BuyHandler implements InvocationHandler {
    private Object target;

    public BuyHandler(Object object) {
        super();
        this.target = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(target, args);
    }

    public static void main(String[] args) {
        Buy proxy = (Buy) Proxy.newProxyInstance(People.class.getClassLoader(),
                People.class.getInterfaces(), new BuyHandler(new People()));
        proxy.buyCar();
    }
}
